﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Repositories;
using Repositories.Interfaces;
using System.Globalization;

namespace AsiaSnackExpress
{
    public partial class DetailCategoryMeal : System.Web.UI.UserControl
    {
        IMealRepository _mealRep;
        public IMealRepository MealRep
        {
            get
            {
                if (_mealRep == null)
                {
                    _mealRep = DIHelper.Resolve<IMealRepository>();
                }
                return _mealRep;
            }

        }

        ICategoryRepository _categoryRep;
        public ICategoryRepository CategoryRep
        {
            get
            {
                if (_categoryRep == null)
                {
                    _categoryRep = DIHelper.Resolve<ICategoryRepository>();
                }
                return _categoryRep;
            }

        }

        public List<Meal> MealDataSource
        {
            get
            {
                return (List<Meal>)repMeals.DataSource;
            }
            set
            {
                if (value != null && value.Count > 0)
                {
                    repMeals.DataSource = value;
                    repMeals.DataBind();
                }
                else
                    this.Visible = false;
            }
        }

        int categoryOrder;
        public int CategoryOrder
        {
            get
            {
                return categoryOrder;
            }
            set
            {
                categoryOrder = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MealRep.Refresh();
                CategoryRep.Refresh();
                Category current = CategoryRep.GetCategoryByOrder(CategoryOrder);
                if (current != null)
                {
                    MealDataSource = MealRep.GetAllMealByCategory(current.Id);
                    txtTitle.Text = current.NameByLanguage;
                }
                else
                    this.Visible = false;
            }

        }
    }
}